// export const arrayTurnObject = (list: []) => {
//
// })
interface Address {
    provinceCode: string;
    provinceName: string;
    cityCode: string;
    cityName: string;
    regionCode: string;
    regionName: string;
    addressPart?: {
        [key: string]: string;
    };
}

interface codeKeys {
    regionCode: string;
    cityName: string;
    provinceCode: string;
    cityCode: string;
    regionName: string;
    provinceName: string
}

// 对象转数组回显
export const addressEcho = (record: Address, keys?: codeKeys): object => {
    if (record[keys.provinceCode] || record[keys.cityCode] || record[keys.regionCode]) {
        try {
            record.addressPart = {
                provinceCode: record[keys.provinceCode],
                provinceName: record[keys.provinceName],
                cityCode: record[keys.cityCode],
                cityName: record[keys.cityName],
                regionCode: record[keys.regionCode],
                regionName: record[keys.regionName]
            }
        } catch (e) {
            console.log(e, 'e')
        }
    }
    return record
}
// 数组转对象提交
export const addressSubmit = (record: Address, keys?: codeKeys) => {
    try {
        record[keys.provinceCode] = record.addressPart.provinceCode
        record[keys.provinceName] = record.addressPart.provinceName
        record[keys.cityCode] = record.addressPart.cityCode
        record[keys.cityName] = record.addressPart.cityName
        record[keys.regionCode] = record.addressPart.regionCode
        record[keys.regionName] = record.addressPart.regionName
        delete record.addressPart
        return record
    } catch (e) {
        console.log(e, 'e')
        return record
    }
}